*------------------------------------------------------------------------------------------------------------%	
* Figure 1: Voluntary employer and state minimum wages in the U.S., 2010-2023
*------------------------------------------------------------------------------------------------------------%	
	use $data/minimum_wages/all_mw.dta, clear

	* Fill in state abbreviations for states to be highlighted
	replace stateabb="CA" if statefips==6 & stateabb==""
	replace stateabb="DC" if statefips==11 & stateabb==""
	replace stateabb="NY" if statefips==36 & stateabb==""

	* Create variable corresponding to most recent employer MW policy to be used to pick out latest employer policies
	egen max_monthly_date=max(monthly_date),by(employer_name min_mw) 

	* Restrict to national employer policies
	drop if coverage_geo!="national" & employer_id!=.

	* Drop policies below the federal minimum
	drop if min_mw<7.25 | mean_mw<7.25

	* Drop policies greater than $16
	replace min_mw=18 if min_mw>17 & employer_id!=.

	* Print text for figure code
	levelsof statefips, local(levels)
		foreach l of local levels {
			   di "|| connected mean_mw monthly_date if statefips==`l', msymbol(none) lcolor(black%20) ///"
		}
		
	levelsof locality_id, local(levels)
		foreach l of local levels {
			   di "|| connected mean_mw monthly_date if locality_id==`l', msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///"
		}		

	twoway connected min_fed_mw monthly_date, lcolor("$dnwbrown") msymbol(none) caption("Fed MW" "    ", ring(0) pos(8) color("$dnwbrown"))  ///
	|| connected mean_mw monthly_date if statefips==2 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==4 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==5 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==6 & locality_id==., msymbol(none) lcolor("$dnwblue") ///
	|| connected mean_mw monthly_date if statefips==8 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==9 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==10 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==11 & locality_id==., msymbol(none) lcolor("$dnwblue") ///
	|| connected mean_mw monthly_date if statefips==12 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==15 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==17 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==23 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==24 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==25 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==26 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==27 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==29 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==30 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==31 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==32 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==34 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==35 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==36 & locality_id==., msymbol(none) lcolor("$dnwblue")  ///
	|| connected mean_mw monthly_date if statefips==39 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==41 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==44 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==46 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==50 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==51 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==53 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| connected mean_mw monthly_date if statefips==54 & locality_id==., msymbol(none) lcolor(black%20) ///
	|| scatter mean_mw monthly_date if monthly_date==755  & locality_id==. & (statefips==6 |statefips==11 | statefips==36), msymbol(i) mlabel(stateabb) mlabcolor("$dnwblue") ///
	|| connected mean_mw monthly_date if locality_id==1, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==2, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==3, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==4, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==5, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==6, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==7, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==8, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==9, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==10, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==11, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==12, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==13, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==14, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==15, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==16, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==17, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==18, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==19, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==20, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==21, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==22, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==23, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==24, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==25, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==26, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==27, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==28, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==29, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==30, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==31, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==32, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==33, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==34, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==35, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==36, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==37, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==38, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==39, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==40, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==41, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==42, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==43, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==44, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==45, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==46, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==47, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==48, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==49, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==50, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==51, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==52, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==53, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==54, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==55, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==56, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| connected mean_mw monthly_date if locality_id==57, msymbol(none) lcolor(black%20) lpattern(dash) lwidth(thin) ///
	|| scatter min_mw monthly_date if employer_id!=. & (n_employees_global==. | n_employees_global<150000) & coverage_geo=="national" & monthly_date==max_monthly_date, msymbol(Oh) mcolor("$dnwcrimson"%20) msize(small) legend(order(5 "High State MWs" 90 "Local MWs" 91 "Company-wide VMWs (Emp < 150k)" 92 "Company-wide VMWs (Emp 150k+)" ) rows(5) ring(0) pos(11) size(small)) ///
	|| scatter min_mw monthly_date if employer_id!=. & n_employees_global!=. & n_employees_global>=150000 & monthly_date==max_monthly_date, msize(large) msymbol(Oh) mcolor("$dnwcrimson"%20) ///
	yline(7.25, lwidth(thick) lcolor("$dnwbrown") lpattern(solid)) ytitle("") yla(8 "$8" 10 "$10" 12 "$12" 14 "$14" 16 "$16" 18 "$18+", nogrid)  xla(,nogrid) xtitle("") graphregion(margin(l+0 r+10)) ysize(3.5) xsize(6)
	graph export "$figures_tables/fig1_us_mw_vmw.pdf", replace
	
*------------------------------------------------------------------------------------------------------------%	
* Figure A1: Voluntary employer minimum wages
*------------------------------------------------------------------------------------------------------------%	

	* Get 3-digit NAICS codes and names
	import excel using "$data/cb/raw/[Project Name].xlsx", sheet("Avg. Hourly Pay NAICS") cellrange(A4:B92) clear firstrow
	drop if er_naics==.
	rename NAICSD er_naics_name
	tempfile industry_names
	save `industry_names'	

	* Get 2-digit NAICS codes and names from census.gov (URL: https://www.census.gov/programs-surveys/economic-census/year/2022/guidance/understanding-naics.html)
	insheet using "$data/cb/documentation/naics2d_names.csv", clear names
	tempfile naics2d_names
	save `naics2d_names'
	
	use "$data/employer_vmw/clean_employer_voluntary_minimum_wages.dta", clear
	gen er_naics=substr(string(naics_dnb),1,3)
	keep if coverage_geo=="national" 
	destring er_naics, replace
	merge m:1 er_naics using `industry_names'
	drop if _merge==2
	drop _merge
	gen naics2d=substr(string(naics_dnb),1,2)
	replace naics2d="44-45" if naics2d=="44" | naics2d=="45"
	replace naics2d="31-33" if naics2d=="31" | naics2d=="32" | naics2d=="33" 
	replace naics2d="48-49" if naics2d=="48" | naics2d=="49"
	merge m:1 naics2d using `naics2d_names'
	*egen employer_tag=tag(parent_company year)
	*keep if employer_tag==1
	replace n_employees_global=1600000 if regexm(employer_name, "Walmart")
	replace n_employees_global=1100000 if regexm(employer_name, "Amazon")
	drop if missing(employer_name)
	
	preserve
	contract emp_key n_employees_global naics2d naics2d_name
	collapse (sum) n_employees_global, by(naics2d naics2d_name)
	egen tot_employees=sum(n_employees_global)
	gen industry_share=round((n_employees_global*100)/tot_employees,2)
	gsort - industry_share
	list naics2d_name industry_share
	restore
	
	preserve
	
		collapse (count) emp_key (sum) n_employees_global,by(year)

		graph tw bar emp_key year, color("$dnwblue") xlabel(2013(1)2023, nogrid) xtitle("") yla(0(5)25,nogrid) ytitle("") ///
		|| scatter emp_key year, msymb(none) mlab(emp_key) mlabcolor(black) mlabpos(12) legend(off) ///
		caption("Industry share of employment covered by VMWs" ///
		"Retail Trade: 70%" ///
		"Finance and Insurance: 18%" ///
		"Accommodation and Food Services: 6%" ///
		"Information: 4%" , size(small) ring(0) pos(10) linegap(1.1)) ytitle("No." "of" "firms", orient(horizontal))
		graph export "$figures_tables/appendix/figa1_number_of_employers_with_vmws.pdf", replace
	
	restore

	preserve
	
		sort emp_key date_start
		by emp_key: gen N = _n
		keep if N == 1
		
		collapse (count) emp_key (sum) n_employees_global,by(year)

		graph tw line emp_key year, color("$dnwblue") xlabel(2013(1)2023, nogrid) xtitle("") yla(,nogrid) ytitle("") ///
		ytitle("No." "of" "new" "adopters", orient(horizontal))
		graph export "$figures_tables/appendix/figa2_number_of_employers_with_vmws_first.pdf", replace
	
	restore
	
	split sources, parse(;)
	foreach var of varlist employer_name sources* {
		replace `var' = trim(`var')
	}
	foreach var of varlist sources* {
		replace `var' = subinstr(`var', "&", "\&", .)
		replace `var' = subinstr(`var', "%", "\%", .)
		replace `var' = subinstr(`var', "$", "\\\$", .)
		replace `var' = subinstr(`var', "_", "\_", .)
	}
	foreach var of varlist employer_name coverage_worker_details {
		replace `var' = subinstr(`var', "&", "\&", .)
		replace `var' = subinstr(`var', "%", "\%", .)
		replace `var' = subinstr(`var', "$", "\\\$", .)
	}
	replace employer_name = "Walmart, Inc." if employer_name == "Walmart" 
	replace coverage_worker_details = subinstr(coverage_worker_details, `"""',  "", .)
	replace coverage_worker_details = trim(coverage_worker_details)
	replace coverage_worker_details = strupper(substr(coverage_worker_details), 1, 1) + substr(coverage_worker_details, 2, .)
	gsort employer_name announce_date
	
	* Full sample
	count
	cap file close myfile
	file open myfile using "$figures_tables/appendix/tablea1_events.txt", write replace
	file write myfile "\footnotesize \begin{threeparttable} \begin{tabular}{lcccccp{0.15\linewidth}} \toprule \toprule" _n "Company & No. Global Employees & Previous MW & New MW & Announce Date & Start Date & Coverage Details \\" _n "\midrule" _n
	file open myfilesources using "$figures_tables/appendix/tablea1_events_sources.txt", write replace
	file write myfilesources "\footnotesize \begin{threeparttable} \begin{tabular}{p{0.6\linewidth}} " _n "Sources \\" _n 
	local s 0
	foreach i of numlist 1/`r(N)' {
		local employer_name = employer_name[`i']
		local employees: di %12.0gc n_employees_global[`i']
		if n_employees_global[`i'] == .{
			local employees ""
		}
		local prev_min_mw = prev_min_mw[`i'] 
		if prev_max_mw[`i'] == . | prev_max_mw[`i'] ==  prev_min_mw[`i'] {
			local prev_mw "\\$`prev_min_mw'"
		}
		else {
			local prev_max_mw = prev_max_mw[`i']
			local prev_mw "\\$`prev_min_mw'-\\\$`prev_max_mw'"
		}
		if prev_min_mw[`i'] == . {
			local prev_mw ""
		}
		local min_mw = min_mw[`i'] 
		if max_mw[`i'] == . | max_mw[`i'] == min_mw[`i'] {
			local mw "\\$`min_mw'"
		else {
		}
			local max_mw = max_mw[`i']
			local mw "\\$`min_mw'-\\\$`max_mw'"
		}
		local announce_date: di %tdMonth_dd,_CCYY announce_date[`i']
		local start_date: di %tdMonth_dd,_CCYY date_start[`i']
		local coverage = coverage_worker_details[`i']
		foreach num of numlist 1/4 {
			local sources`num' = sources`num'[`i']
			if "`sources`num''" == "" {
				local sources`num' ""
				local s`num' ""
			}
			else {
				local s = `s'+1
				local sources`num' "`s'. \url{`sources`num''}} \\ "
				if `num' == 1 {
					local s`num' "^{`s'}"
				}
				else {
					local s`num' "^{, `s'}"
				}
			}
		}
		file write myfile "`employer_name'`s1'`s2'`s3'`s4' & `employees' & `prev_mw' & `mw' & `announce_date' & `start_date' & `coverage' \\" _n
		file write myfilesources "`sources1'`sources2'`sources3'`sources4'"
		if mod(`i', 22) == 0 {
			file write myfile "\bottomrule \bottomrule \end{tabular}  \end{threeparttable} \end{table}" _n
			file write myfile "\newpage \begin{table} \footnotesize \begin{threeparttable} \begin{tabular}{lcccccp{0.15\linewidth}} \toprule \toprule" _n "Company & No. Global Employees & Previous MW & New MW & Announce Date & Start Date & Coverage Details \\" _n "\midrule" _n
		}
		if mod(`i', 15) == 0 {
			file write myfilesources "\end{tabular}  \end{threeparttable} \end{table}" _n
			file write myfilesources "\newpage \begin{table} \footnotesize \begin{threeparttable} \begin{tabular}{p{0.6\linewidth}} " _n "Sources \\" _n
		}
	}
	file write myfile "\bottomrule \bottomrule \end{tabular}  \end{threeparttable}"
	file close myfile
	file write myfilesources "\end{tabular}  \end{threeparttable}"
	file close myfilesources
	
